
//
//  CNStatusButtonView.swift
//  Ccweibo
//
//  Created by 陈锦聪 on 16/3/26.
//  Copyright © 2016年 Coco. All rights reserved.
//

import UIKit

protocol CNStatusButtonViewDelegate: NSObjectProtocol {
    func didClickRetweetButton()
    func didClickCommentButton()
}

class CNStatusButtonView: UIView {
    
    weak var delegate: CNStatusButtonViewDelegate?
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }
    
    private func prepareUI() {
        
        addSubview(retweetBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        addSubview(forwardSeparator)
        addSubview(backwardSeparator)
        
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.leading.top.bottom.equalTo(self)
            make.trailing.equalTo(commentBtn.snp_leading)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.width.equalTo(retweetBtn)
            make.width.equalTo(likeBtn)
        }
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.trailing.top.bottom.equalTo(self)
            make.leading.equalTo(commentBtn.snp_trailing)
        }
        forwardSeparator.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        backwardSeparator.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    @objc private func retweetBtnAction() {
        delegate?.didClickRetweetButton()
    }
    @objc private func commentBtnAction() {
        delegate?.didClickCommentButton()
    }
    private lazy var retweetBtn: UIButton = {
        let button = UIButton(title: "转发", imageName: "timeline_icon_retweet")
        button.addTarget(self, action: "retweetBtnAction", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    private lazy var commentBtn: UIButton = {
        let button = UIButton(title: "评论", imageName: "timeline_icon_comment")
        button.addTarget(self, action: "commentBtnAction", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    private lazy var likeBtn: UIButton = UIButton(title: "赞", imageName: "timeline_icon_unlike")
    private lazy var forwardSeparator: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
    private lazy var backwardSeparator: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
  }
